﻿using SPSDeploy.Extensions.Modules.Extract;
using System.Xml.Linq;

namespace SPSDeploy.Extensions.Controllers
{
    /// <summary>
    /// Extract operation controller
    /// </summary>
    public class ExtractController : BaseController
    {

        // Private members
        private readonly string fileName;

        /// <summary>
        /// Initialization
        /// </summary>
        /// <param name="fileName"></param>
        public ExtractController(string fileName)
        {
            this.fileName = fileName;
        }

        /// <summary>
        /// Execute operation
        /// </summary>
        public override void Execute()
        {
            OnProgressMessage("Extract started.");
            XElement root = new XElement("root");
            XElement farm = new FarmModule(this).Execute(root);
            XElement serviceApplications = new ServiceApplicationModule(this).Execute(farm);
            XElement serviceApplicationProxies = new ServiceApplicationProxyModule(this).Execute(farm);
            new SearchModule(this).Execute(serviceApplications);
            new SearchProxyModule(this).Execute(serviceApplicationProxies);
            root.Save(fileName);
            OnProgressMessage("Extract completed.");
        }

    }
}